package com.bw.paper;

import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.Editable;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.bw.paper.utils.LogUtils;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * 使用特殊字符[哼]->对应一张图片
 * SpannableString->使用图片替换掉对应的特殊字符
 * 在TextView 或Editext显示时->显示的为特殊字符-
 *
 *
 * */

public class TestEmojiActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tv;
    private EditText edt;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_channel_head);
//        findViewById(R.id.send_btn).setOnClickListener(this::onClick);
//        findViewById(R.id.get_emoji_btn).setOnClickListener(this::onClick);
//        tv = findViewById(R.id.emoji_tv);
//        edt = findViewById(R.id.emoji_edt);
    }

    @Override
    public void onClick(View v) {
        if (R.id.send_btn==v.getId()){
            SpannableString string = new SpannableString("[哼]");
            ImageSpan span = new ImageSpan(BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher));
            string.setSpan(span,0,3,SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
            if (edt.getText()==null) {
                edt.setText(string);
            }else {
                Editable editable =  edt.getText();
                editable.append(string);
                edt.setText(editable);
            }
            tv.setText(edt.getText());
        }else {
            LogUtils.show("TestEmojiActivity:"+edt.getText().toString());
        }
    }
}
